public abstract class Tree<Element extends Comparable> {
	
	protected Node root = null;
	
	public Tree(Element element) {
		root = new Node(element);
	}
	
	public Tree() {}

	protected class Node<Element extends Comparable> {
		private Element element;
		private Node left = null;
		private Node right = null;
		private Node previous = null;
		private Node next = null;

		Node(Element element) {
			this.element = element;
		}
		
		public Element getElement() {
			return element;
		}

		public Node getLeft() {
			return left;
		}

		public void setLeft(Node left) {
			this.left = left;
		}

		public Node getRight() {
			return right;
		}

		public void setRight(Node right) {
			this.right = right;
		}

		public Node getPrevious() {
			return previous;
		}

		public void setPrevious(Node previous) {
			this.previous = previous;
		}

		public Node getNext() {
			return next;
		}

		public void setNext(Node next) {
			this.next = next;
		}	
	}
	
	protected class Iterator<Element extends Comparable> implements TreeIter<Element> {

		protected Node node;			// iterator position
		
		public Iterator() {
			this.node = root;
		}
		
		public Iterator(Node node) {
			this.node = node;
		}
		
		@Override
		public Element next() {			// get next list element
			if (node == null) {
				return null;
			}
			Element element = (Element) node.getElement();
			node = node.getNext();
			return element;
		}

		@Override
		public Element previous() {			// get prev list element
			if (node == null) {
				return null;
			}
			Element element = (Element) node.element;
			node = node.getPrevious();
			return element;
		}

		@Override
		public boolean hasNext() { 		// more elements?
			if (node == null) {
				return false;
			}
			return node != null;
		}

		@Override
		public boolean hasPrevious() { 		// more elements?
			return node.previous != null;
		}

		@Override
		public TreeIter down() {
			return null;
		}
	}
	
	abstract public TreeIter contains(Element element);

	public TreeIter iterator() {
		//return this.contains((Element)root.getElement());
		return new Iterator<Element>(this.root);
	}

	abstract public Iter<Boolean> search(Element element);

	abstract public void add(Element element);
}
